<?php
declare (strict_types=1);

namespace app\command;

use api\channel\fake\FakeChannel;
use app\common\service\order\coupon_order\fake_order\FakeOrder;
use app\model\Agent;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
use think\facade\Console;

class BuildOrder extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('buildorder')
            ->setDescription('php think buildorder 111')//111 为代理商id agent_id
            ->addArgument('agent_id', Argument::OPTIONAL, "your name")
            ->addArgument('serv_type', Argument::OPTIONAL, "your name")
            ->addArgument('user_id', Argument::OPTIONAL, "your name")
            ->setDescription('Say Hello');

    }

    protected function execute(Input $input, Output $output)
    {

        if (isProd()) return;

        $agent_id = $input->getArgument('agent_id');
        $serv_type = $input->getArgument('serv_type');
        $user_id = $input->getArgument('user_id');

        $serv_type = $serv_type??12;


        if (!$agent_id) {
            $output->writeln('请输入代理商id 格式为： php think buildorder 1111 其中111 是代理id');
            return;
        }



        if (!Agent::where('id',$agent_id)->find()){
            $output->writeln('不存在代理商');
            return;
        }


        $service = new FakeOrder($agent_id,$serv_type,$user_id);

        $service->setExtendApi(new FakeChannel())->httpGetOrder();




//        $output = Console::call('cron:run');

        // 指令输出
        $output->writeln('buildorder');
    }
}
